<template>
  <div>
    <el-table
      :data="pageInfo.list"
      border
      align="center"
      stripe
      ref="multipleTable"
      tooltip-effect="dark"
      style="
        border-radius: 10px;
        width: 68%;
        margin: 0px auto;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
      ">
      <el-table-column type="selection" width="55%" prop="id"> </el-table-column>
      <el-table-column
        prop="order_id"
        label="订单Id"
        width="80"></el-table-column>
      <el-table-column prop="order_vehicle_code" label="车牌号" width="120%">
      </el-table-column>
      <el-table-column prop="order_startime" label="开始时间" width="180%">
      </el-table-column>
      <el-table-column prop="order_endtime" label="结束时间" width="180%">
      </el-table-column>
      <el-table-column prop="order_money" label="金额" width="100%">
      </el-table-column>
      <el-table-column prop="order_state" label="订单状态" width="100%">
      </el-table-column>
      <el-table-column label="订单确认" width="175%">
        <template slot-scope="scope">
          <el-button type="primary" round   @click="zt_Order_Complete01(scope.row)">确认交易完成</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="金额确认"   :visible.sync="dialogFormVisible">
      <el-form >
       当前租借费用：{{cost+"元"}}
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary"  @click="zt_Order_CompleteFinal">确 定</el-button>
      </div>
    </el-dialog>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.pageNum"
      :page-sizes="[3, 5, 10, 15, 20]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
  </div>
</template>
<script>
export default {
  inject:['reload'],
  data() {
    return {
    pickerOptions: {
        shortcuts: [{
        text: '最近一周',
        onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }]
    },
      pageInfo: {},
      pageSize: 5,
      currentPage: 1,
      dates:'',
      vehicle_code:'',
      cost:0.0,
      dialogTableVisible: false,
      dialogFormVisible: false,
      Order1: {
        order_id: "",
        order_startime: "",
        order_stall_id: "",
        order_user_id:""
      }
    };
  },
  methods: {
    zt_selOrder_conduct(){
       var id = sessionStorage.getItem('userId');
      this.$axios
        .get("/zt_selOrder_conduct", {
          params: {
            pageSize: this.pageSize,
            currentPage: this.currentPage,
            user_id:id
          }
        })
        .then((res) => {
          if(res.data.data != null){
            this.pageInfo = res.data.data;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.zt_selOrder_conduct();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.zt_selOrder_conduct();
      console.log(`当前页: ${val}`);
    },
    zt_Order_Complete01(item){
      this.Order1.order_startime = item.order_startime;
      this.Order1.order_stall_id = item.order_stall_id;
      this.Order1.order_id = item.order_id;
      this.$axios
        .get("/zt_Order_Complete01",{
          params:{
            start_time:item.order_startime,
            stall_id:item.order_stall_id
          }
        })
        .then((res) => {
          this.cost = res.data.data;
          this.dialogFormVisible = true;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    zt_Order_CompleteFinal(){
      var id = sessionStorage.getItem('userId');
      this.Order1.order_user_id = id;
      console.log(this.Order1.order_id);
      console.log(this.Order1.order_startime);
      console.log(this.Order1.order_stall_id);
      console.log(this.Order1.order_user_id);
      this.$axios
        .post("zt_Order_CompleteFinal",this.Order1)
        .then((res) => {
          this.dialogFormVisible=false;
          this.reload();
          alert(res.data.messages);
        })
        .catch((error) => {
          console.log(error);
        });
    }
  },
  mounted() {
    this.zt_selOrder_conduct();
  },
};
</script>